﻿//-----------------------------------------------------------------------
// <copyright file="Job.cs" company="Nathan Miller">
// Copyright (c) Nathan Miller.
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
//-----------------------------------------------------------------------
namespace TileTool.Base.Threading.Job.Generic
{
    using TileTool.Base.Threading.Future.Generic;
    using TileTool.Threading.Future.Generic;
    using TileTool.Threading.Job.Generic;

    /// <summary>
    /// Abstract base class for all jobs that produce a result.
    /// 
    /// Derived classes only need to override Execute().
    /// </summary>
    /// <typeparam name="ResultType">Result type for the job.</typeparam>
    public abstract class Job<ResultType> : Job, IJob<ResultType>
    {
        #region Constructor

        /// <summary>
        /// Default constructor.
        /// </summary>
        public Job()
            : base(new Future<ResultType>())
        {
        }

        #endregion

        #region Properties - Public

        /// <summary>
        /// Gets or sets the result value for the job.
        /// </summary>
        public ResultType Result
        {
            get
            {
                return this.Future.Result;
            }

            protected set
            {
                this.GenericFuture.Result = value;
            }
        }

        /// <summary>
        /// Gets the future object associated with the job.
        /// </summary>
        public new IFuture<ResultType> Future
        {
            get
            {
                return (IFuture<ResultType>)base.Future;
            }
        }

        #endregion

        #region Properties - Private

        /// <summary>
        /// Gets the base class Future as the generic future used
        /// in the constructor.
        /// </summary>
        private Future<ResultType> GenericFuture
        {
            get
            {
                return (Future<ResultType>)this.Future;
            }
        }

        #endregion
    }
}
